"""
数学运算魔法函数
"""


class Number(object):
    def __init__(self, num):
        self.num = num

    def __abs__(self):
        """
        绝对值
        """
        return abs(self.num)


class MyVector(object):
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, other):
        """
        向量相加
        """
        res = MyVector(self.x + other.x, self.y + other.y)
        return res

    def __str__(self):
        return "x:{x}, y:{y}".format(x=self.x, y=self.y)


if __name__ == '__main__':
    num = Number(-18)
    print(abs(num))
    # 输出结果：
    """
    18
    """

    first_vector = MyVector(1, 2)
    second_vector = MyVector(3, 4)
    print(first_vector + second_vector)
    # 输出结果：
    """
    x: 4, y: 6
    """
